<#assign module="errand"/>

<@override name="header">
<link rel="stylesheet" href="${ctx}/assets/css/datetimepicker.css">
</@override>

<@override name="body">
<div class="row">
	<div class="col-md-3">
			<@shiro.hasPermission name='errand'>
				<div class="btn-group">
		  			<a class="btn btn-default" href="${ctx}/errand/list">执行中</a>
		  			<a class="btn btn-default" href="${ctx}/errand/refuselist">拒单</a>
		  			<a class="btn btn-default active" href="${ctx}/errand/noreview">未评价</a>
		  			<a class="btn btn-default" href="${ctx}/errand/cancellist">已销单</a>
		  			<a class="btn btn-default" href="${ctx}/errand/finishlist">已完成</a>
	  			</div>
  			</@shiro.hasPermission>	
	</div>
	<div class="col-md-9">
		<form class="form-inline" role="form">
		    <@shiro.isMainCompany>
				<div class="form-group">
					<select class="form-control" name="companyId">
						<option value="">--全部公司--</option>
						<#if companys??>
							<#list companys as company>
								<option value="${company.id}" <#if companyId?? && companyId==company.id>selected="selected"</#if>>${company.abbreviation?if_exists}</option>
							</#list>
						</#if>
					</select>
			    </div>
		    </@shiro.isMainCompany>
		    <div class="form-group">
	            <input class="form-control" id="startTime" name="start" value="${startTime?if_exists}" placeholder="开始时间"  readonly="readonly" type="text" >
	        </div> 
	        <div class="form-group">
	        	<input class="form-control" id="endTime" name="end" value="${endTime?if_exists}" placeholder="结束时间"  readonly="readonly" type="text" >
	        </div>
			<div class="form-group">
			    <input type="text" class="form-control" name="param" value="${param?if_exists}" placeholder="模糊搜索">
		  	</div>
		  	<button type="submit" class="btn btn-default"><i class="icon-search"></i>&nbsp;搜索</button>
		  	<button class="pull-right button button-rounded button-flat-blue" onclick="window.open('${ctx}/errand/add', '_blank', 'height=770,width=1220,scrollbars=yes,resizable=yes,alwaysRaised=yes,toolbar=no');"><i class="icon-plus"></i>&nbsp;添加新订单</button>
			<button class="pull-right button button-rounded button-flat-blue" onclick="window.location.reload(true);"><i class="icon-refresh"></i>&nbsp;刷新</button>
	    </form>
	</div>
</div>
<div class="row margin-top">
	<div class="col-xs-12">
		<div class="panel panel-primary">
		<div class="table-responsive">
			<table class="table table-hover table-striped">
					<thead>
						<tr>
							<th>订单号</th>
							<th>下单时间</th>
							<@shiro.isMainCompany>
							<th>所属公司</th>
							</@shiro.isMainCompany>
							<th>客户</th>
							<th>服务人员</th>
							<th>任务标题</th>
							<th>订单定价(元)</th>
							<th>交付地址</th>
							<th>交付时间</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
					<#if (page.content)?? >
					<#list page.content as order>
						<td  align="center"><a  href="${ctx}/errand/detail/${order.id}" class="btn-link">${order.orderNo?if_exists}</a></td>
						<td  align="center">${order.created?string('yyyy-MM-dd HH:mm')}</td>
						<@shiro.isMainCompany>
						<td>${order.companyName?if_exists}</td>
						</@shiro.isMainCompany>
						<td  align="center">${order.passengerName?if_exists}-${order.passengerPhone?if_exists}</td>
						<td  align="center">${order.employName?if_exists}-${order.employPhone?if_exists}</td>
						<td  align="center" style="max-width:100px;">${order.title?if_exists}</td>
						<td  align="center">${order.shouldPay!"无"}</td>
						<td  align="center">${order.deliverAddress?if_exists}</td>
						<td  align="center">${order.deliverTime?string('yyyy-MM-dd HH:mm')}</td>
						<td align="center">
							<a href="#" class="modifyCash" orderId="${order.id}" orderNo="${order.orderNo}"	 orderMemo="${order.memoStr?if_exists}" >备注</a>
							<a href="#" orderId="${order.id}" orderNo="${order.orderNo}"  class="review">评价</a>
							<a href="javascript:;" class="btn-link" onclick="window.open('${ctx}/errand/addmore/${order.id}', '_blank', 'height=770,width=1220,scrollbars=yes,resizable=yes,alwaysRaised=yes,toolbar=no');">追加</a>
						</td>
						</tr>
					</#list>	
				</#if>
					</tbody>
				</table>
			<#if page.totalElements??>
			 <ul class="pagination pull-right pagination-sm">
				<li><a>共 ${page.totalElements} 条数据</a></li>
				<@pg.pager items=page.totalElements?number maxPageItems=20 export="currentPageNumber=pageNumber" url="${ctx}/errand/noreview">
					<@pg.param name="startTime" value="${startTime?if_exists}"/>
					<@pg.param name="endTime" value="${endTime?if_exists}"/>
					<@pg.param name="param" value="${param?if_exists}"/>
					<@shiro.isMainCompany>
						<@pg.param name="companyId" value="${companyId?if_exists}"/>
					</@shiro.isMainCompany>
					<@pg.index>
						<@pg.first>
							<li><a href="${pageUrl}">&laquo;</a></li>
						</@pg.first>
						<@pg.prev>
							<li><a href="${pageUrl}">&lsaquo;</a></li>
						</@pg.prev>
						<@pg.pages>
							<#if  currentPageNumber == pageNumber >
								<li class="active"><a href="#">${pageNumber}</a></li>
							<#else>
								<li><a href="${pageUrl}">${pageNumber}</a></li>
							</#if>
						</@pg.pages>
						<@pg.next>
							<li><a href="${pageUrl}">&rsaquo;</a></li>
						</@pg.next>
						<@pg.last>
							<li><a href="${pageUrl}">&raquo;</a></li>
						</@pg.last>
					</@pg.index>
				</@pg.pager>
			   </ul>
			</#if>
		</div>
	  </div>
	</div>
</div>

<!--添加备注-->
<div class="form-horizontal">
	<div class="modal fade" id="dialog_modifyCash">
	   <div class="modal-dialog">
	     <div class="modal-content">
	    	<div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	        	<h4 class="modal-title">添加备注</h4>
	        </div>
		    <div class="modal-body">
	      	<form action=""  method="post">
	      		<input type="hidden" id="orderId2"/>
	      		
		      	<div class="form-group">
	      	 		<label class="col-sm-3 control-label">订单号：</label>
                    <div class="col-sm-8">
                    	<label  class="control-label" id="orderNo2" ></label>
                    </div>
		        </div>
		         <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                    	<textarea class="form-control" cols="60"  id="memo" rows="3" required></textarea>
                    </div>
				 </div>
		         <div class="form-group">
                    <label class="col-sm-3 control-label">原有备注：</label>
                    <div class="col-sm-8">
                    	<textarea class="form-control" cols="60"  id="oldmemo" rows="6"></textarea>
	                </div>
				 </div>
				   <div class="form-group">
                 	  <div class="col-sm-6">
                	  </div>
                	  <div class="col-sm-3">
					      <input  type="button" class="btn btn-primary" id="save" value="确定">
					      <button type="button" class="btn btn-default" id="close_modal_memo">关闭</button>
		        	  </div>
		           </div>  
		  	</form>
	     	</div>
	     </div>
	  </div>
	</div>
</div>

<!--评价-->
<div class="form-horizontal">
	<div class="modal fade" id="dialog_review">
	   <div class="modal-dialog">
	     <div class="modal-content">
	    	<div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	        	<h4 class="modal-title">评价</h4>
	        </div>
		    <div class="modal-body">
	      	<form action="${ctx}/errand/review"  method="post">
	      		<input type="hidden" id="orderId" name="id"  />
      			<input type="hidden"  id="starLevel" />
		      	<div class="form-group">
	      	 		<label class="col-sm-3 control-label">订单号:</label>
                    <div class="col-sm-8">
                    	<label  class="control-label" id="orderNo" ></label>
                    </div>
		        </div>
		         <div class="form-group">
                    <label class="col-sm-3 control-label">评分：</label>
                    <div id="rateDiv" class="col-sm-1 form-control-static" style="width:70px;">
                    </div>
                    <div class="col-sm-2 form-control-static">
                    	<div id="rateChose"></div>
                    </div>
                </div>
		         <div class="form-group">
                    <label class="col-sm-3 control-label">评价内容:</label>
                    <div class="col-sm-8">
                    	<textarea class="form-control" cols="60" name="content"  rows="3" ></textarea>
                    </div>
				 </div>
				   <div class="form-group">
                 	  <div class="col-sm-6">
                	  </div>
                	  <div class="col-sm-3">
					      <input  type="submit" class="btn btn-primary" value="确定">
					      <button type="button" class="btn btn-default" id="close_modal_review">关闭</button>
		        	  </div>
		           </div>  
		  	</form>
	     	</div>
	     </div>
	  </div>
	</div>
</div>

</@override>
<@override name="footer">
<script src="${ctx}/assets/js/bootstrap-datetimepicker.min.js"></script>
<script src="${ctx}/assets/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${ctx}/assets/js/jquery.raty.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$("#startTime").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true });
		$("#endTime").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true });
		
		$('#endTime').change(function(){
			  var begin=new Date($('#startTime').val().replace(/-/g,"/"));
		      var end=new Date($('#endTime').val().replace(/-/g,"/"));
		   	   if(begin!=null&&end!=null&&begin-end>=0){
	  				 $('#endTime').val("");
	  				 $.scojs_message("截止日期要在开始日期之后!", $.scojs_message.TYPE_ERROR);
		      	}
	 	});
	 	 $('#startTime').change(function(){
			  var begin=new Date($('#startTime').val().replace(/-/g,"/"));
		      var end=new Date($('#endTime').val().replace(/-/g,"/"));
		   	   if(begin!=null&&end!=null&&begin-end>=0){
	  				 $('#endTime').val("");
	  				 $.scojs_message("开始日期要在截止日期之前!", $.scojs_message.TYPE_ERROR);
		      	}
		 });
//评价
	$(".review").click(function(){
		$('#orderId').val($(this).attr('orderId'));
		$('#orderNo').html($(this).attr('orderNo'));
		$('#dialog_review').modal();
	});
	$("#close_modal_review").click(function(){
		$('#dialog_review').modal("hide");
	});
	rat('rateChose',1);
 	function rat(star,m){
			star= '#' + star;
			$(star).raty({
				path: "${ctx}/assets/css/images",
				starOff: 'star-off-big.png',
				starOn: 'star-on-big.png',
				starHalf: 'star-half-big.png',
				size: 24,
				start: 5,
				half:true,
				targetKeep : true,
				number:5,
				score:5,
				click: function (score, evt) {
					$("#starLevel").val(score*m);
					$("#rateDiv").html(score*m+"星");
				}
			});
		}
//备注		
$(".modifyCash").click(function(){
		var  orderId2=$(this).attr('orderId');
		var orderNo2=$(this).attr('orderNo');
		var orderMemo=$(this).attr('orderMemo');
		$('#orderId2').val(orderId2);
		$('#orderNo2').html(orderNo2);
		$('#oldmemo').val(orderMemo);
    	$('#dialog_modifyCash').modal();
    });
    $("#save").click(function(){
	     	$('#dialog_modifyCash').modal("hide");
				$.post('${ctx}/errand/remark',{'id':$('#orderId2').val(),'memo':$('#memo').val()},function(data){
		           if(data.success){
		                $.scojs_message(data.message, $.scojs_message.TYPE_OK);
		                setTimeout(function(){
							window.location.reload(true);
						}, 1000);
			       }else{
		                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
		                setTimeout(function(){
							window.location.reload(true);
						}, 1000);
			       }
			    },'json');
     });
    $("#close_modal_memo").click(function(){
		$('#dialog_modifyCash').modal("hide");
	});
		 
	});		
</script>
</@override>
<@extends name="../layout.ftl"/>
